package com.emps_vue.demo.Service;

import com.emps_vue.demo.Dao.DaoSaveUser;
import com.emps_vue.demo.Entity.User;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class RegesterServiceImpl implements RegesterService {
    @Resource
    private DaoSaveUser daoSaveUser;


    @Override
    public void register(User user) {
        User user1 = daoSaveUser.findByName(user.getUsername());
        if (user1 == null) {
            user.setStatus("已激活");
            user.setRegisterTime(new Date());
            daoSaveUser.save(user);
        } else {
            throw new RuntimeException("用户名已存在！");
        }
    }

    @Override
    public User login(User user) {
        User user2 = daoSaveUser.login(user);
        if (!ObjectUtils.isEmpty(user2)) {
            return user2;
        } else {
            throw new RuntimeException("用户名不正确或密码不正确！");
        }
    }
}


